class Patient{
    patientName= ''
    patientSex= 1
    patientAge= ''
    patientWeight= ''
    patientPhone= ''
    patientIdcard= ''
    patientBirthday= ''
    relationship= ''
    patientAddress= ''
    pmh= ''
    amh= ''
    fmh= ''
    nurse= ''
    liver= ''
    renal= ''
    is_default= 0
    id= ''


    initData(data) {
        this.patientName = data.patientName
        this.patientSex = data.patientSex
        this.patientAge = data.patientAge
        this.patientWeight = data.patientWeight
        this.patientPhone = data.patientPhone
        this.patientIdcard = data.patientIdcard
        this.patientBirthday = data.patientBirthday.length>10?data.patientBirthday.substring(0,11):''
        this.relationship = data.relationship
        this.patientAddress = data.patientAddress
        this.pmh = data.pmh
        this.amh = data.amh
        this.fmh = data.fmh
        this.nurse = data.nurse
        this.liver = data.liver
        this.renal = data.renal
        this.is_default = data.is_default
        this.id = data.id
    }

    setHealthyInfo(type,data){
        if(type==='pmh'){
            this.pmh = data
        } else if(type==='amh'){
            this.amh = data
        } else if(type==='fmh'){
            this.fmh = data
        } else if(type==='nurse'){
            this.nurse = data
        } else if(type==='liver'){
            this.liver = data
        } else if(type==='renal'){
            this.renal = data
        }
    }

    getHealthyInfo(type){
        if(type==='pmh'){
            return this.pmh
        } else if(type==='amh'){
            return this.amh
        } else if(type==='fmh'){
            return this.fmh
        } else if(type==='nurse'){
            return this.nurse
        } else if(type==='liver'){
            return this.liver
        } else if(type==='renal'){
            return this.renal
        }
    }

    changeDefaultData() {
        if(this.is_default==1){
            this.is_default = 0
        } else {
            this.is_default = 1
        }
    }

    changeRelationShop(data) {
        this.relationship = data
    }

    getValues() {
        return {
            patientName: this.patientName,
            patientSex: this.patientSex,
            patientAge: this.patientAge,
            patientWeight: this.patientWeight,
            patientPhone: this.patientPhone,
            patientIdcard: this.patientIdcard,
            patientBirthday: this.patientBirthday,
            relationship: this.relationship,
            patientAddress: this.patientAddress,
            pmh: this.pmh,
            amh: this.amh,
            fmh: this.fmh,
            nurse: this.nurse,
            liver: this.liver,
            renal: this.renal,
            is_default: this.is_default,
            id: this.id
        }
    }

    //通过身份证获取出生年月
    setBirthdayFromIdCard() {
        let idCard = this.patientIdcard
        let birthday = "";
        if(idCard != null && idCard != ""){
            if(idCard.length == 15){
                birthday = "19"+idCard.substr(6,6);
            } else if(idCard.length == 18){
                birthday = idCard.substr(6,8);
            }

            birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-");
        }
        this.patientBirthday = birthday
    }

    setAge() {
        let identityCard = this.patientIdcard
        let len = (identityCard + "").length;
        if (len == 0) {
            return 0;
        } else {
            if ((len != 15) && (len != 18))//身份证号码只能为15位或18位其它不合法
            {
                return 0;
            }
        }
        let strBirthday = "";
        if (len == 18)//处理18位的身份证号码从号码中得到生日和性别代码
        {
            strBirthday = identityCard.substr(6, 4) + "/" + identityCard.substr(10, 2) + "/" + identityCard.substr(12, 2);
        }
        if (len == 15) {
            strBirthday = "19" + identityCard.substr(6, 2) + "/" + identityCard.substr(8, 2) + "/" + identityCard.substr(10, 2);
        }
        //时间字符串里，必须是“/”
        let birthDate = new Date(strBirthday);
        let nowDateTime = new Date();
        let age = nowDateTime.getFullYear() - birthDate.getFullYear();
        //再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
        if (nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())) {
            age--;
        }
        this.patientAge = age
    }


}

export {
    Patient
}
